package org.gwt.grin.rebind.commands;

import java.util.Formatter;

import org.gwt.grin.client.commands.ActivateSegmentCommand;
import org.gwt.grin.rebind.SECommand;
import org.gwt.grin.rebind.SESegment;
import org.gwt.grin.rebind.ShowBuilder;

import com.google.gwt.uibinder.rebind.IndentedWriter;

public class SEActivateSegmentCommand extends SECommand {

	private final boolean push;
	private final boolean pop;
	private SESegment segment;

	public SEActivateSegmentCommand(boolean push, boolean pop) {
		this.push = push;
		this.pop = pop;
	}

	public void setSegment(SESegment segment) {
		this.segment = segment;
	}

	@Override
	public String write(ShowBuilder builder) {
		String cn = ActivateSegmentCommand.class.getName();
		Formatter formatter = new Formatter();
		formatter.format("new %s(showInstance, %b, %b)", cn, push, pop);
		return formatter.toString();
	}

	public void setup(IndentedWriter w, ShowBuilder builder) {
		if (segment != null) {
			String vn = getVN(builder);
			w.write("%s.setup(%s);", vn, segment.getVN(builder));
		}
	}

	@Override
	protected String getClassName() {
		return ActivateSegmentCommand.class.getName();
	}

}
